package com.ys.otms.services.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ys.otms.dao.IBillsDao;
import com.ys.otms.dto.BillsDto;
import com.ys.otms.dto.ConsumeDto;
import com.ys.otms.dto.ParamDto;
import com.ys.otms.services.IBillsServices;
import com.ys.otms.utils.*;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/9/17.
 */
@Service
public class BillsServiceImpl implements IBillsServices {

    private static Logger logger = LoggerFactory.getLogger(BillsServiceImpl.class);

    @Autowired
    private IBillsDao iBillsDao;
    @Override
    public  Map<String, Object> selectBillsQuery(HttpServletRequest request,ParamDto paramDto) throws Exception {
        logger.info("BillsServiceImpl selectBillsQuery start obj{}",paramDto);
        paramDto.setBillsStatus(1);
        paramDto.setUserId(Integer.parseInt((String) request.getSession().getAttribute("SESSION_COMPANY_ID")));
        List<BillsDto> billsDtoList = iBillsDao.selectBillsQuery(paramDto);
        int billsCount = iBillsDao.selectBillsByCount(paramDto);
        Map<String,Object> map = new HashMap<>();
        for (int i = 0; i < billsDtoList.size(); i++) {
            billsDtoList.get(i).setBills_Time(billsDtoList.get(i).getBillsTime().toString().substring(0,billsDtoList.get(i).getBillsTime().toString().indexOf(".")));
        }
        map.put("data",billsDtoList);
        map.put("count",billsCount);
        return map;
    }

}
